uniform sampler2D textBase;
uniform float distortionValue;

// Renvoi la couleur en niveau de gris
vec4 grayScale(vec4 baseColor)
{
	return baseColor.r * 0.299 + baseColor.g * 0.587 + baseColor.b * 0.114;
}

vec4 noiseEffect(vec4 baseColor)
{
	vec4 noise = vec4(0,0,0,1);
	vec2 tst = gl_TexCoord[0].st + vec2(distortionValue/8,distortionValue/8);
	if(tst.x <=1.0 && tst.y <= 1.0)
	{
		noise = texture2D(textBase, tst);
	}
	
	vec4 result = mix(noise,vec4(1,1,1,1),distortionValue)/3.0f + 2.0*baseColor/3.0f;
	return result;
}
void main()
{
	vec2 st = gl_TexCoord[0].st;
	st.x += sin(st.x*20*1/distortionValue)*(0.03*distortionValue);
	gl_FragColor = noiseEffect(grayScale(texture2D(textBase,st)));
}
